<template>
  <div style="display: flex; justify-content: center; align-items: center; height: 100vh;">
    <div style="padding:400px; text-align: center;">
      <div style="font-weight: bold; font-size: 30px; margin-top: -100px;margin-bottom: 50px;">医保报销</div>

    <el-form :model="form" label-width="120px" >
      <div>参保人信息</div>
      <el-form-item label="申报人编号">
        <el-input  style="width: 220px; height: 80%" v-model="form.id"/>
      </el-form-item>
      <el-form-item label="申报人姓名">
        <el-input  style="width: 220px; height: 80%" v-model="form.name"/>
      </el-form-item>
      <div>药品信息</div>
      <el-form-item label="药品名称">
        <el-input  style="width: 220px; height: 80%" v-model="form.dname"/>
      </el-form-item>
      <el-form-item label="药品数量">
        <el-input-number v-model="form.dtq" :precision="0" :step="1" :min="0" :max="10" />
      </el-form-item>
      <div>诊疗项目信息</div>
      <el-form-item label="诊疗项目名称">
        <el-input  style="width: 220px; height: 80%" v-model="form.tname"/>
      </el-form-item>
      <el-form-item label="诊疗项目数量">
        <el-input-number v-model="form.ttq" :precision="0" :step="1" :min="0" :max="10" />
      </el-form-item>
      <div>服务设施信息</div>
      <el-form-item label="服务设施名称">
        <el-input  style="width: 220px; height: 80%" v-model="form.fname"/>
      </el-form-item>
      <el-form-item label="服务设施数量">
        <el-input-number v-model="form.ftq" :precision="0" :step="1" :min="0" :max="10" />
      </el-form-item>

<!--      <el-form-item label="附件">-->
<!--        <el-upload action="/api/files/upload" :on-success="filesUploadSuccess1">-->
<!--          <el-button type="primary">上传附件</el-button>-->
<!--        </el-upload>-->
<!--      </el-form-item>-->
      <div style="text-align: center;">
        <el-button type="primary" size="large" @click="apply">申请报销</el-button>
      </div>
    </el-form>




  </div>
    </div>

</template>

<script>

import request from "../../utils/request";

export default {
  name: 'Student',
  components: {
  },
  data(){
    return{
      form:{
        id:'',
        name:'',
        dname:'',
        dtq:'',
        tname:'',
        ttq:'',
        fname:'',
        ftq:''
      },
      search:'',
      tableData: [],
      people: [],
      drugs: [],
      treats: [],
      facilitys: []
    }
  },
  created(){
    this.loadPeople();
    this.loadDrugs();
    this.loadTreats();
    this.loadFacilitys();

  },
  methods:{
    async loadPeople() {
      try {
        const People = require('./models/People'); // 引入模型定义
        this.people = await People.findAll(); // 查询所有用户并存储在people变量中
      } catch (error) {
        console.error('加载人员数据出错', error);
        // 处理错误情况
      }
    },
    async loadDrugs() {
      try {
        const Drug = require('./models/Drug');
        this.drugs = await Drug.findAll();
      } catch (error) {
        console.error('加载药物数据出错', error);
        // 处理错误情况
      }
    },
    async loadTreats() {
      try {
        const Treat = require('./models/Treat');
        this.treats = await Treat.findAll();
      } catch (error) {
        console.error('加载诊疗项目数据出错', error);
        // 处理错误情况
      }
    },
    async loadFacilitys() {
      try {
        const Facility = require('./models/Facility');
        this.facilitys = await Facility.findAll();
      } catch (error) {
        console.error('加载服务设施数据出错', error);
        // 处理错误情况
      }
    },
    apply(){
      // 遍历表people对应的id列，检查是否存在匹配的数据
      // const matchedId = this.people.find(person => person.id === this.form.id);
      // if (!matchedId) {
      //   this.$message.error('ID不存在');
      //   return;
      // }
      //
      // // 遍历表people对应的name列，检查是否存在匹配的数据
      // const matchedName = this.people.find(person => person.name === this.form.name);
      // if (!matchedName) {
      //   this.$message.error('姓名不存在');
      //   return;
      // }
      //
      // const matchedDname = this.drugs.find(drug => drug.dname === this.form.dname);
      // if (!matchedDname) {
      //   this.$message.error('药品不存在');
      //   return;
      // }
      //
      // const matchedTname = this.treats.find(treat => treat.tname === this.form.tname);
      // if (!matchedTname) {
      //   this.$message.error('诊疗项目不存在');
      //   return;
      // }
      //
      // const matchedFname = this.facilitys.find(facility => facility.fname === this.form.fname);
      // if (!matchedFname) {
      //   this.$message.error('服务设施不存在');
      //   return;
      // }

      request.post("/student/apply1", this.form).then(res => {
        console.log(this.form)
        console.log(this.res)
        this.$message({type: "success", message: "申请成功!"})
      })
    }
    ,

    filesUploadSuccess1(res){
      console.log(res)
      this.form["附件"]=res.data
    },



  }
}
</script>
